package com.nbsaas.boot;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class FindDuplicates {
    public static void main(String[] args) {
        int[] array = {1, 3, 5, 6, 78, 85, 11, 2, 3, 4, 5, 4};

        Map<Integer, Long> countMap = Arrays.stream(array)
                .boxed()
                .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

        System.out.println("重复元素及其出现次数：");
        countMap.entrySet().stream()
                .filter(entry -> entry.getValue() > 1)
                .forEach(entry -> System.out.println("元素 " + entry.getKey() + " 重复了 " + entry.getValue() + " 次。"));
    }
}
